package hng.config;

import hng.interceptor.CorsInterceptor;
import hng.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    CorsInterceptor corsInterceptor(){
        return new CorsInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(corsInterceptor()).addPathPatterns("/**");

        registry.addInterceptor(new LoginInterceptor())
                //拦截的路径
                .addPathPatterns("/user/update-info", "/cart/*" , "/user/info" ,"/address/*","/comment/*",
                    "/order/*/**","/user/update-password", "/store/*/**", "/admin/*/**"
                )

                //排查不拦截的路径
                .excludePathPatterns("/api/user/*/send_phone_code")
                .excludePathPatterns();

        WebMvcConfigurer.super.addInterceptors(registry);

    }

}
